package com.ccys.app.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ccys.app.service.AppVersionService;
import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.entity.TblAppVersion;
import com.ccys.db.mapper.TblAppVersionMapper;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.vo.app.launchingTheApp.VersionMake;
import com.ccys.db.vo.app.launchingTheApp.VersionVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: WhiteCoat
 * @description: 版本号管理
 * @author: ZhangJingCan
 * @create: 2024-01-13 16:24
 **/

@Service
public class AppVersionServiceImpl extends BaseServiceImpl<TblAppVersion> implements AppVersionService {

    @Resource
    private TblAppVersionMapper tblAppVersionMapper;

    @Override
    public ResponseResultApp<VersionVo> getAppVersion() {
        List<TblAppVersion> tblAppVersions = tblAppVersionMapper.getListAppVersion();
        VersionVo versionVo = new VersionVo();
        for (TblAppVersion version : tblAppVersions) {
            VersionMake make = new VersionMake();
            //基础设置
            make.setVersion_code(version.getVersioncode());
            make.setVersion_name(version.getVersionname());
            make.setDownload_url(version.getUrl());
            //是否强制更新：0-否，1-是，需要返回的是true和false  -  实体类字段为integer - 这里判断返回boolean
            make.setForce_update(version.getAppStatus() != 0);
            make.setMessage(version.getMessage());

            //1:ios 2:android 3:huawei
            if (ObjectUtil.isNotEmpty(version) && 1 == version.getOsPlatform()) {
                //ios
                versionVo.setIos(make);
            } else if (ObjectUtil.isNotEmpty(version) && 2 == version.getOsPlatform()) {
                //android
                versionVo.setAndroid(make);
            } else if (ObjectUtil.isNotEmpty(version) && 3 == version.getOsPlatform()) {
                //huawei
                versionVo.setHuawei(make);
            }
        }
        return ResponseResultApp.success(versionVo);
    }
}
